<?
	include("../includes/main_inc.php");
	$r= new ReturnRecord();  // base object for returning data or raw queries
	
	if($_GET['id']) $id=$_GET['id'];
	elseif ($_POST['id']) $id=$_POST['id'];
	
	if($_POST['Submit']){
		if($_POST['Amount']>0){
			$_POST['affiliateID']=$id;
			$m= new AddToDatabase();
			$m->AddPosts($_POST,$_FILES);
			$m->AddTable("Payments");
			$m->AddSkip(array("id"));
			$m->AddFunctions(array("PayDate"=>"NOW()"));
			$m->DoStuff();
			//echo $m->SQL;
			if($m->Errors==""){
				$SQL="UPDATE affiliate SET Account=Account-$_POST[Amount] WHERE id=$id";
				$r->RawQuery($SQL);
				$Message="Payment Added";
			}else{
				$Message=$m->Errors;
			}
		}
	};
	
	
	$r->AddTable("affiliate");
	$r->AddSearchVar($id);
	$Insert=$r->GetRecord();
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Affiliate Bubble Administration</title>

<link href="<?=$rootdir?>css/admin.css" rel="stylesheet" type="text/css">
<script src="<?=$rootdir?>jscript/menuArray.js" language="javascript"></script>
<script src="<?=$rootdir?>jscript/clock.js" language="javascript"></script>
<script>
	function SetPaymentType(){
		var PType=document.getElementById("paymentMethod").value;
		if(PType=="Deposit"){
			var CBank="";
			var CCheque="none";
		}else{
			var CBank="none";
			var CCheque="";
		}
		for(x=1;x<5;x++){
			document.getElementById("bankRow"+x).style.display=CBank;
		}
		for(x=1;x<7;x++){
			document.getElementById("chqRow"+x).style.display=CCheque;
		}
	}
</script>
</head>

<body onLoad="funClock();">
<?php include("../includes/header.php"); ?>
<table width="100%" border="0" cellspacing="25" cellpadding="0">
<tr>
<td valign="top" width="240"><div id="menu"><?php include("../menu/affiliatesmenu.php"); ?></div></td>
<td align="center" valign="top">

<div id="titleCompact">Pay An Affiliate </div>

<div id="descriptionCompact"></div>

<div id="contentCompact">
<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#E9EEF5">
<tr id="formHeader">
<td><strong>Enter Payment details</strong><strong></strong></td>
</tr>
<tr>
  <td align="center" bgcolor="#FFFFFF"><form name="form1" method="post" action="pay.php">
    <table width="100%" border="0" cellspacing="3" cellpadding="0">
      <tr>
        <td>Affiliate</td>
        <td><?=$Insert['contactName']?></td>
      </tr>
      <tr>
        <td>Amount Owed </td>
        <td>$
          <?=$Insert['Account']?></td>
      </tr>
      <tr>
        <td>Amount To Pay </td>
        <td><input name="Amount" type="text" id="Amount" value="<?=$Insert['Account']?>"></td>
      </tr>
      <tr>
        <td><input name="id" type="hidden" id="id" value="<?=$id;?>"></td>
        <td><label>
          <input type="submit" name="Submit" value="Submit">
        </label></td>
      </tr>
    </table>
  </form>
  </td>
</tr>
</table>

</div>

</td>
</tr>
</table>
</body>
</html>
